﻿using MediatR;
using Traceability.App.Api.Application.Command.Get;
using Traceability.App.Domain;
using Traceability.App.ErrorCode;
using Traceability.App.Instructure;

namespace Traceability.App.Api.Application.Handler.Get
{
    public class GetYangCompanyHandler : IRequestHandler<GetYangCompanyCommand, ApiResult<AquaculturefarmCompanyModel>>
    {
        private readonly IBaseRepository<AquaculturefarmCompanyModel> aquacultureRepo;

        public GetYangCompanyHandler(IBaseRepository<AquaculturefarmCompanyModel> aquacultureRepo) 
        {
            this.aquacultureRepo = aquacultureRepo;
        }
        public Task<ApiResult<AquaculturefarmCompanyModel>> Handle(GetYangCompanyCommand request, CancellationToken cancellationToken)
        {
            ApiResult<AquaculturefarmCompanyModel> res = new ApiResult<AquaculturefarmCompanyModel>();
            var company = aquacultureRepo.GetAll().Where(x => x.Batch == request.Batch).FirstOrDefault();
            res.Code = ApiEnum.Success;
            res.Data = company;
            res.Msg = "显示养殖场企业成功";
            return Task.FromResult(res);
        }
    }
}
